﻿//javascript functions of add relation dialog-box

//get add relation grid data
function get_addRelationData(node_id, dimname, table_name, hier_id, comboid, txt_date) {
    ////debugger;

    $.ajax({
        async: true,
        type: 'POST',
        url: "Callback.aspx?operation=get_griddataAddRel&node_id=" + node_id + "&dimname=" + dimname + "&hier_id=" + hier_id + "&table_name=" + table_name + "&txtdate=" + txt_date,
        success: function (str) { //griddata
            //alert("k");
            ////debugger;
            var result = eval('(' + str + ')');
            var url = "Callback.aspx?operation=get_griddataAddRelDRow&node_id=" + node_id + "&dimname=" + dimname + "&hier_id=" + hier_id + "&table_name=" + table_name + "&txtdate=" + txt_date;

            fillgrid(result, "#dataGrid", "#pager", "800px", "350px", url,true);
            jQuery("#dataGrid").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, search: true });
            //            //debugger;
            //            jQuery("#dataGrid").jqGrid('navGrid', "#pager",
            //            { edit: false, add: false, del: false, search: true },
            //                {},
            //                {},
            //                {},
            //                {
            //                    //multipleSearch: true,
            //                    // multipleGroup: true,
            //                    //showQuery: true ,
            //                    odata: ['equal', 'not equal', 'less', 'less or equal', 'greater', 'greater or equal', 'begins with', 'does not begin with', 'is in', 'is not in', 'ends with', 'does not end with', 'contains', 'does not contain']
            //                }
            //            );
        },
        loadError: function (xhr, status, error) {
            ////debugger;
            alert('error');
        }

    });
}

//add relation of selected dimensions to selected node 
function addRelation() {

    ////debugger;
    var dimname = $("#hid_dimname").val();
    //add the relation to that node
    add_relaion(dimname, "#dataGrid");
}

//add the relation of dimension
function add_relaion(dimname, tblgrid) {
   // //debugger;

    var Ids = jQuery(tblgrid).getGridParam('selarrrow');
    var node_id = $("#hid_NodeId").val();
    var table_name = $("#hid_TableName").val();
    var hier_id = $("#hid_HierarchyId").val();
    var vers_id = $("#hid_versid").val();
    var txtdate = $("#hid_txtdate").val();   

    if (Ids != undefined) {
        if (Ids.length != 0 && node_id != undefined) {
            $.ajax({
                async: true,
                type: 'POST',
                url: "Callback.aspx?operation=add_rel&dimname=" + dimname + "&hier_id=" + hier_id + "&node_id=" + node_id + "&Ids=" + Ids + "&vers_id=" + vers_id + "&txtdate=" + txtdate + "&table_name=" + table_name,
                success: function (data) {
                   // //debugger;
                    //var result = eval('(' + data + ')');
                    // refreshgrid(result, "#dataGrid");
                    var url = "Callback.aspx?operation=get_griddataAddRelDRow&node_id=" + node_id + "&dimname=" + dimname + "&hier_id=" + hier_id + "&table_name=" + table_name + "&txtdate=" + txtdate;

                    refreshgrid(data, tblgrid,url);

                    //if added the relation setting boolean to refresh 
                    //exist and unassigned grid
                    $("#hid_ret").val('true');
                }
            });
        }
        else {
            alertmsgAddRel(Ids, node_id);
        }
    }
    else {
        alertmsgAddRel(Ids, node_id);
    }
}


function closeDlg() {
    //flag for refresh of exist and un-assgined grid,
    //if we have added relation

    //debugger;
    window.returnValue = $("#hid_ret").val();  
    //window.close();
}

function closeDlgCall() {
    //debugger;
    //flag for refresh of exist and un-assgined grid,
    //if we have added relation
    window.close();
}

